﻿using Dilon.Core;
using Furion.DatabaseAccessor;
using Furion.DatabaseAccessor.Extensions;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using System.Linq;
using System.Threading.Tasks;

namespace Dilon.Application
{
    /// <summary>
    /// 6666服务
    /// </summary>
    [ApiDescriptionSettings(Name = "sys_app", Order = 100)]
    public class sys_appService : Isys_appService, IDynamicApiController, ITransient
    {
        private readonly ISqlSugarRepository<sys_app> _rep;

        public sys_appService(ISqlSugarRepository<sys_app> rep)
        {
            _rep = rep;
        }

        /// <summary>
        /// 分页查询6666
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet("/sys_app/page")]
        public async Task<dynamic> Page([FromQuery] sys_appInput input)
        {
            var entities = await _rep.Context.Queryable<sys_app>()
                                     .ToPagedListAsync(input.PageNo, input.PageSize);
            return XnPageResult<sys_app>.SqlSugarPageResult(entities);
        }

        /// <summary>
        /// 增加6666
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("/sys_app/add")]
        public async Task Add(Addsys_appInput input)
        {
            var entity = input.Adapt<sys_app>();
            await _rep.InsertAsync(entity);
        }

        /// <summary>
        /// 删除6666
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("/sys_app/delete")]
        public async Task Delete(Deletesys_appInput input)
        {
            var entity = await _rep.FirstOrDefaultAsync(u => u.Id == input.Id);
            await _rep.DeleteAsync(entity);
        }

        /// <summary>
        /// 更新6666
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("/sys_app/edit")]
        public async Task Update(Updatesys_appInput input)
        {
            var entity = input.Adapt<sys_app>();
            await _rep.Context.Updateable(entity).IgnoreColumns(ignoreAllNullColumns:true).ExecuteCommandAsync();
        }

        /// <summary>
        /// 获取6666
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet("/sys_app/detail")]
        public async Task<sys_app> Get([FromQuery] Queryesys_appInput input)
        {
            return await _rep.FirstOrDefaultAsync(u => u.Id == input.Id);
        }

        /// <summary>
        /// 获取6666列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet("/sys_app/list")]
        public async Task<dynamic> List([FromQuery] sys_appInput input)
        {
            return await _rep.ToListAsync();
        }
    }
}
